package wxdb.query;

import wxdb.tx.Transaction;
import wxdb.ui.Global;
import wxdb.metadata.*;
import wxdb.record.*;

/** The Plan class corresponding to a table.
  * @author Edward Sciore
  */
public class TablePlan implements Plan {
   private TableInfo ti;
   String tablename;
   String fieldname;
   /**
    * Creates a leaf node in the query tree corresponding
    * to the specified table.
    * @param tblname the name of the table
    * @param tx the calling transaction
    */
   public TablePlan(String tblname , String fldname) {
	   tablename = tblname;
	   fieldname = fldname;
	   ti = TableMgr.getMeta(Global.currentdb, tblname);
   }
   
   public String getTableName(){
	   return tablename;
   }
   
   public String getFieldName(){
	   return fieldname;
   }
   /**
    * Creates a table scan for this query.
    * @see simpledb.query.Plan#open()
    */
   public Scan open() {
      return new TableScan(ti,tablename,fieldname);
   }
   
   /**
    * Estimates the number of block accesses for the table,
    * which is obtainable from the statistics manager.
    * @see simpledb.query.Plan#blocksAccessed()
    */ 
   public int blocksAccessed() {
      return ti.getPageNum();
   }
   
   /**
    * Determines the schema of the table,
    * which is obtainable from the catalog manager.
    * @see simpledb.query.Plan#schema()
    */
   public Schema schema() {
      return ti.getSchema();
   }
}
